package com.bluestarenergy.provisioning.engine.batch.item.callback;

import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;

import com.bluestarenergy.provisioning.engine.batch.item.processor.CustomerBusinessProcessor;
import com.bluestarenergy.provisioning.engine.batch.item.reader.CustomerItemReader;
import com.bluestarenergy.provisioning.engine.domain.CustomerCredit;

public class CustomerRepeatCallback implements RepeatCallback{

	private CustomerItemReader reader;
	private CustomerBusinessProcessor processor;
	
	public void setItemReader(CustomerItemReader reader) {
		this.reader = reader;
	}

	public void setItemProcessor(CustomerBusinessProcessor processor) {
		this.processor = processor;
	}

	public RepeatStatus doInIteration(RepeatContext context) throws Exception {

		CustomerCredit dataRead = reader.read();
		if (dataRead == null){
			return RepeatStatus.FINISHED;
		}

		CustomerCredit processedData = processor.process(dataRead);
		System.out.println("For input data " + dataRead.getName() + ", the processed data is " + processedData.getName());

		return RepeatStatus.CONTINUABLE;
		
	}

}
